package com.itheima.common;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R SQLIntegrityConstraintViolationException(SQLIntegrityConstraintViolationException ec){
        String message = ec.getMessage();
        String s = message.split(" ")[2];
        return R.error(s+"已经存在");
    }

    @ExceptionHandler(CustomerException.class)
    public R CustomerException(CustomerException ec){
        String message = ec.getMessage();
        return R.error(message);
    }
}
